//
//  RMZQTableViewCell.m
//  Cartoon
//
//  Created by dllo on 15/10/29.
//  Copyright © 2015年 YSZ. All rights reserved.
//

#import "RMZQTableViewCell.h"
#import "RMZQCollectionViewCell.h"
#import "PrefixHeader.pch"
#import "Recommend1.h"
static NSString  *recommendID = @"RMZQCollectionViewCell";

@implementation RMZQTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
    {
        self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
        if (self) {
        
            
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
        flowLayout.itemSize = CGSizeMake(100 * WIDTH, 130 *HEIGHT);
        // 横向滑动
        flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        // 每个之间的间距
        
        flowLayout.minimumInteritemSpacing = 8 * WIDTH;
        flowLayout.minimumLineSpacing = 10 * WIDTH;
        self.collectionView =[[UICollectionView alloc] initWithFrame:self.contentView.bounds collectionViewLayout:flowLayout];
        [self.contentView addSubview:_collectionView];
        flowLayout.sectionInset = UIEdgeInsetsMake(10 * WIDTH, 10 *HEIGHT , 10* WIDTH, 10  *HEIGHT);
        _collectionView.showsHorizontalScrollIndicator = false;
            _collectionView.backgroundColor =[UIColor clearColor];
           
        self.titleLabel = [[UILabel alloc] init];
        [self.contentView addSubview:_titleLabel];
        self.button = [UIButton buttonWithType:UIButtonTypeSystem];
           
            [self.contentView addSubview:_button];
            
            
        }
        return self;
    
    
    
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
    
        _collectionView.frame = CGRectMake(0, 80 *HEIGHT  ,600 * WIDTH , 220 * HEIGHT);
         [_collectionView registerClass:[RMZQCollectionViewCell class] forCellWithReuseIdentifier:recommendID];
    _titleLabel.frame = CGRectMake(10, 40 * HEIGHT, 120 * WIDTH, 30 * HEIGHT);
    _titleLabel.font = [UIFont systemFontOfSize:20];
    _titleLabel.textColor = [UIColor colorWithRed:13 / 255.0 green:184 / 255.0 blue: 240 / 255.0 alpha:1];
    
    _button.frame = CGRectMake(330 * WIDTH, 40 * HEIGHT, 45 * WIDTH, 30 * HEIGHT);
    _button.font = [UIFont systemFontOfSize:20 * WIDTH];
    _button.tintColor = [UIColor colorWithRed:13 / 255.0 green:184 / 255.0 blue: 240 / 255.0 alpha:1];    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return _dataArray.count;
  

}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    RMZQCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:recommendID forIndexPath:indexPath];

    Recommend1 *recommend = [_dataArray objectAtIndex:indexPath.item];
    
    cell.smallTitleLabel.text = recommend.title;
   
    cell.lastupLabel.text = [NSString stringWithFormat:@"更新至%@",recommend.lastup];
    [cell.RMZQimage sd_setImageWithURL:[NSURL URLWithString:recommend.src_cover_url]placeholderImage:[UIImage imageNamed:@"5"]];
    

    return cell;


}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    
    return 1;
}

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{

    return CGSizeMake( WIDTH * 115, HEIGHT * 140);
    

}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    Recommend1 *recommend =_dataArray[indexPath.row];
    [self.delegate pushRecommend:recommend];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
